package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysProblem;
import com.ruoyi.system.service.ISysProblemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题Controller
 * 
 * @author ruoyi
 * @date 2025-10-28
 */
@RestController
@RequestMapping("/system/problem")
public class SysProblemController extends BaseController
{
    @Autowired
    private ISysProblemService sysProblemService;

    /**
     * 查询问题列表
     */
    @PreAuthorize("@ss.hasPermi('system:problem:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysProblem sysProblem)
    {
        startPage();
        List<SysProblem> list = sysProblemService.selectSysProblemList(sysProblem);
        return getDataTable(list);
    }

    //@PreAuthorize("@ss.hasPermi('system:problem:list')")
    @GetMapping("/noPagelist")
    public TableDataInfo noPagelist(SysProblem sysProblem)
    {
        List<SysProblem> list = sysProblemService.selectSysProblemList(sysProblem);
        return getDataTable(list);
    }

    /**
     * 导出问题列表
     */
    @PreAuthorize("@ss.hasPermi('system:problem:export')")
    @Log(title = "问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysProblem sysProblem)
    {
        List<SysProblem> list = sysProblemService.selectSysProblemList(sysProblem);
        ExcelUtil<SysProblem> util = new ExcelUtil<SysProblem>(SysProblem.class);
        util.exportExcel(response, list, "问题数据");
    }

    /**
     * 获取问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:problem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysProblemService.selectSysProblemById(id));
    }

    /**
     * 新增问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:add')")
    @Log(title = "问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysProblem sysProblem)
    {
        return toAjax(sysProblemService.insertSysProblem(sysProblem));
    }

    /**
     * 修改问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:edit')")
    @Log(title = "问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysProblem sysProblem)
    {
        return toAjax(sysProblemService.updateSysProblem(sysProblem));
    }

    /**
     * 删除问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:remove')")
    @Log(title = "问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysProblemService.deleteSysProblemByIds(ids));
    }
}
